var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var BundleConfig = require("AA_BundleConfig");
var EventManager = require("AA_EventManager");
var ResKeeper = require("AA_ResKeeper");
var EvenType = require("AA_EvenType");
var GameDataManager = require("AA_GameDataManager");
var GameGlobalVariable = require("AA_GameGlobalVariable");
var NodePoolMag = require("AA_NodePoolMag");
var UI_Bullet = require("AA_UI_Bullet");
var UI_BulletBang = require("AA_UI_BulletBang");
var UI_BulletBomb = require("AA_UI_BulletBomb");
var UI_BulletMove = require("AA_UI_BulletMove");
var UI_ZhongDu = require("AA_UI_ZhongDu");
var UI_Player = require("AA_UI_Player");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_UI_GameViewMap = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.gridNode = null;
    t.playerNode = null;
    t.bulletNode = null;
    t.mosterNode = null;
    t.boosTip = null;
    t.isok = true;
    t.nowindex = -1;
    t.offtime = 0;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.onEnable = function () {
    var e = this;
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.GAME_UPDATE_BAG, this.initUi, this);
    EventManager.EventMgr.addEventListener(EvenType.EVENT_TYPE.GAME_SHOW_BOOS, this.showBoosTip, this);
    this.isok = true;
    this.scheduleOnce(function () {
      e.isok = false;
      e.initUi();
    }, .5);
  };
  _creator.prototype.showBoosTip = function () {
    var e = this;
    if (!this.boosTip.active) {
      this.boosTip.active = true;
      var t = this.node.getChildByName("gezibg1");
      this.boosTip.width = t.width + 95;
      this.boosTip.height = t.height + 90;
      this.boosTip.opacity = 0;
      cc.tween(this.boosTip).to(.2, {
        opacity: 255
      }).start();
      this.scheduleOnce(function () {
        cc.tween(e.boosTip).to(.2, {
          opacity: 0
        }).call(function () {
          e.boosTip.active = false;
        }).start();
      }, 2);
    }
  };
  _creator.prototype.onGameState = function (e) {
    1 == e && this.huishouNode();
  };
  _creator.prototype.huishouNode = function () {
    var e = this.playerNode.children;
    var t = e.length;
    for (var o = 0; o < t; o++) {
      var n = "player" + (u = e[0]).getComponent(UI_Player.default).playerId;
      u.getComponent(UI_Player.default).resetEff();
      NodePoolMag.NodePoolMag.instance.recycleNode(n, u);
    }
    var i = GameGlobalVariable.GameGlobalVariable.effNode.children;
    for (o = 0; o < i.length; o++) {
      var a = i[o];
      h = a.getComponent(UI_ZhongDu.default);
      if (h) {
        NodePoolMag.NodePoolMag.instance.recycleNode(h.popname, a);
      }
    }
    var r;
    var c = this.bulletNode.children;
    var s = this.bulletNode.children.length;
    for (o = 0; o < s; o++) {
      var u;
      h = (u = c[0]).getComponent(UI_Bullet.default);
      if (h) {
        NodePoolMag.NodePoolMag.instance.recycleNode("bullet_" + h.bulletId, u);
      }
    }
    if (GameGlobalVariable.GameGlobalVariable.liulianNode) {
      GameGlobalVariable.GameGlobalVariable.cleanMoveBullet();
      var l = GameGlobalVariable.GameGlobalVariable.liulianNode.children;
      var d = l.length;
      for (o = 0; o < d; o++) {
        var p = l[0];
        var h = p.getComponent(UI_BulletMove.default);
        NodePoolMag.NodePoolMag.instance.recycleNode("bullet_" + h.bulletId, p);
      }
    }
    if (GameGlobalVariable.GameGlobalVariable.languaNode) {
      var I = (r = GameGlobalVariable.GameGlobalVariable.languaNode.children).length;
      for (o = 0; o < I; o++) {
        h = (E = r[0]).getComponent(UI_BulletBomb.default);
        NodePoolMag.NodePoolMag.instance.recycleNode("bullet_" + h.bulletId, E);
      }
    }
    if (GameGlobalVariable.GameGlobalVariable.playereffNode) {
      I = (r = GameGlobalVariable.GameGlobalVariable.playereffNode.children).length;
      for (o = 0; o < I; o++) {
        var E;
        h = (E = r[0]).getComponent(UI_BulletBang.default);
        NodePoolMag.NodePoolMag.instance.recycleNode("bullet_" + h.bulletId, E);
      }
    }
  };
  _creator.prototype.initUi = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e = this;
      return __generator(this, function () {
        this.isok || new Date().getTime() - this.offtime > 100 && (this.offtime = new Date().getTime(), this.huishouNode(), this.scheduleOnce(function () {
          e.createPlayer();
        }));
        return [2];
      });
    });
  };
  _creator.prototype.createPlayer = function () {
    return __awaiter(this, undefined, undefined, function () {
      var e;
      var t;
      var o;
      var n;
      var i;
      var a;
      var r;
      var c;
      var l;
      var d;
      var p;
      var _;
      var m;
      var y;
      var v;
      var b;
      var I;
      var E;
      var M;
      return __generator(this, function (s) {
        switch (s.label) {
          case 0:
            e = 0;
            t = 0;
            o = 0;
            n = 0;
            i = GameDataManager.GameDataMgr.gameBag.cellWposArray;
            a = Math.max(this.gridNode.children.length, i.length);
            y = 0;
            s.label = 1;
          case 1:
            if (y < a) {
              r = i[y];
              E = this.gridNode.children[y];
              if (r) {
                r = this.gridNode.convertToNodeSpaceAR(r);
                if (!E) {
                  E = cc.instantiate(this.gridNode.children[0]), this.gridNode.addChild(E);
                }
                E.active = true;
                c = E.getChildByName("grid").getComponent(cc.Sprite);
                return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "res/bg/" + GameGlobalVariable.GameGlobalVariable.getSceneId(), cc.SpriteFrame)];
              } else {
                return [3, 3];
              }
            } else {
              return [3, 5];
            }
          case 2:
            l = s.sent();
            c.spriteFrame = l;
            E.x = r.x;
            E.y = r.y;
            E.x < e && (e = E.x);
            E.x > t && (t = E.x);
            E.y > n && (n = E.y);
            E.y < o && (o = E.y);
            return [3, 4];
          case 3:
            E && (E.active = false);
            s.label = 4;
          case 4:
            y++;
            return [3, 1];
          case 5:
            d = this.node.getChildByName("gezibg1");
            p = d.getComponent(cc.Sprite);
            return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "res/bg/gezibg" + GameGlobalVariable.GameGlobalVariable.getSceneId(), cc.SpriteFrame)];
          case 6:
            _ = s.sent();
            p.spriteFrame = _;
            d.width = Math.abs(e - t) + 170;
            d.height = Math.abs(o - n) + 170;
            m = GameDataManager.GameDataMgr.gameBag.dressUpEquips;
            y = 0;
            s.label = 7;
          case 7:
            if (!(y < 1)) {
              return [3, 12];
            }
            v = 0;
            s.label = 8;
          case 8:
            if (v < m.length) {
              if (-1 != this.nowindex && this.nowindex != v) {
                return [3, 10];
              } else {
                b = m[v];
                return [4, this._loadRes(BundleConfig.BundleNames.Game, "game/" + "prefabs/player/player" + (b.shuiguoId - 1e3), cc.Prefab)];
              }
            } else {
              return [3, 11];
            }
          case 9:
            I = s.sent();
            if (!(E = NodePoolMag.NodePoolMag.instance.getNode("player" + (b.shuiguoId - 1e3)))) {
              NodePoolMag.NodePoolMag.instance.createNodeCount("player" + (b.shuiguoId - 1e3), 1, I);
              E = NodePoolMag.NodePoolMag.instance.getNode("player" + (b.shuiguoId - 1e3));
            }
            E.active = true;
            M = this.playerNode.convertToNodeSpaceAR(b.wPostion);
            E.x = M.x;
            E.y = M.y;
            this.playerNode.addChild(E);
            E.getComponent(UI_Player.default).initPlayerInfo(this.mosterNode, b);
            s.label = 10;
          case 10:
            v++;
            return [3, 8];
          case 11:
            y++;
            return [3, 7];
          case 12:
            return [2];
        }
      });
    });
  };
  _creator.prototype.onDisable = function () {
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.GAME_UPDATE_BAG, this.initUi, this);
    EventManager.EventMgr.rmEventListener(EvenType.EVENT_TYPE.GAME_SHOW_BOOS, this.showBoosTip, this);
  };
  __decorate([_property(cc.Node)], _creator.prototype, "gridNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "playerNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "bulletNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "mosterNode", undefined);
  __decorate([_property(cc.Node)], _creator.prototype, "boosTip", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_UI_GameViewMap;